#ifndef PACKET_PROCESSING_H
#define PACKET_PROCESSING_H

#include <stdint.h>

// 以太网帧头部结构
typedef struct {
    uint8_t dst_mac[6];
    uint8_t src_mac[6];
    uint16_t ether_type;
} EthernetHeader;

// IP 头部结构
typedef struct {
    uint8_t version_ihl;
    uint8_t tos;
    uint16_t total_length;
    uint16_t identification;
    uint16_t flags_fragment_offset;
    uint8_t ttl;
    uint8_t protocol;
    uint16_t header_checksum;
    uint32_t src_ip;
    uint32_t dst_ip;
} IPHeader;

// 树节点结构
typedef struct TreeNode {
    void (*process)(const uint8_t *, int, struct TreeNode *, void *);
    struct TreeNode *left;
    struct TreeNode *right;
} TreeNode;

// 使用位域定义数据包标志
typedef struct {
    uint8_t is_external : 1;
    uint8_t reserved : 7;
} PacketFlags;

typedef struct {
    // 这里简单假设 IP 地址最多记录 100 个
    char ips[100][16];
    uint64_t traffic[100];
    int count;
} TrafficStats;

void init_traffic_stats(TrafficStats *stats);
void process_packet(const uint8_t *packet, int len, TrafficStats *stats);
TreeNode *build_tree();
void process_packet_through_tree(TreeNode *root, const uint8_t *packet, int len, TrafficStats *stats);
void free_tree(TreeNode *root);

#endif    